package com.fire.control.system.module.notice.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.fire.control.system.dto.NoticeDTO;
import com.fire.control.system.dto.SelectGroupDTO;
import com.fire.control.system.dto.SelectRoleDTO;
import com.fire.control.system.dto.app.AppNoticeVo;
import com.fire.control.system.entity.Notice;
import com.fire.control.system.support.protocol.notice.NoticeRequestProtocol;

public interface NoticeMapper{
	
	@Select("select id,title,notice_content from t_notice where id = #{id}")
	public AppNoticeVo findById(String id);
	
	/**
	 * 
	 * @author: xiechengguang 
	 * @Title: getInValidTime   
	 * @Description: app端获取有效时间内的通知  
	 * @param:        
	 * @return: List<AppNoticeVo>      
	 * @throws
	 */
	public List<AppNoticeVo> getInValidTime(@Param("userId") String userId);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getTitles   
	 * @Description: app端消息标题滚动列表   
	 */
	public List<String> getTitles(@Param("userId") String userId);
	
	public List<Notice> getAll();
	
	public List<NoticeDTO> getAllByCompanyId(@Param("companyId") String id);
	
	public List<SelectGroupDTO> getGroupsByNoticeId(@Param("noticeId") String noticeId);
	
	public List<SelectRoleDTO> getRolesByNoticeId(@Param("noticeId") String noticeId);
	
	@Select("select * from t_notice where id = #{id}")
	public Notice getById(String id);
	
	public void addNotice(Notice notice);
	
	public void updateNotice(Notice notice);
	
	/**
	 * 保存通知-角色关系表数据
	 */
	@Insert("insert into t_notice_role(role_id, notice_id) values(#{roleId}, #{noticeId})")
	public void saveNoticeRole(@Param("roleId") String roleId, @Param("noticeId") String noticeId);
	
	/**
	 * 保存通知-设备组关系表数据
	 */
	@Insert("insert into t_notice_device_group(device_group_id, notice_id) values(#{groupId}, #{noticeId})")
	public void saveNoticeGroup(@Param("groupId") String roleId, @Param("noticeId") String noticeId);
	/**
	 * @author: xiechengguang 
	 * @Title: deleteNoticeRole   
	 * @Description: 删除 通知-角色关系 
	 */
	@Delete("delete from t_notice_role where notice_id = #{noticeId}")
	public void deleteNoticeRole(String noticeId);
	
	/**
	 * @author: xiechengguang 
	 * @Title: deleteNoticeRole   
	 * @Description: 删除 通知-设备组关系   
	 */
	@Delete("delete from t_notice_device_group where notice_id = #{noticeId}")
	public void deleteNoticeGroup(String noticeId);
	
	/**
	 * @author: xiechengguang 
	 * @Title: deleteNoticeByIds   
	 * @Description: 批量删除（软删除）  
	 */
	public void deleteNoticeByIds(@Param("ids") String[] ids); 
	
	/**
	 * @author: xiechengguang 
	 * @Title: searchNotices   
	 * @Description: 按条件搜索消息通知  
	 */
	public List<NoticeDTO> searchNotices(NoticeRequestProtocol noticeRequestProtocol); 
	
	/**
	 * @author: xiechengguang 
	 * @Title: getDetailById   
	 * @Description: TODO  
	 */
	public NoticeDTO getDetailById(@Param("id") String id);
	
	
}
